<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

    <script src="js/js01.js"></script>
    <script>
        /*
        var color = "pink";

        function showColor() {
            console.log(this.color);// window
        }
        
        showColor();
        */

        /*
        var user = {
            color : "red",
            viewColor : showColor
        
        }
        user.viewColor();
        */

        var name = "outer";
        var obj = {
            name : "obj-name",
            sayName : function() {
                var temp = this;//obj
                return function(){
                    return temp.name;
                };
            }
        };

        console.log(obj.sayName()());

        (function(){
           

           /*
            var color = "pink";

            function showColor() {
                console.log(this.color);
            }

            var user = {
                color : "red",
                viewColor : showColor
            
            }
            user.viewColor();

            var user2 = {
                color : "blue",
                viewColor : showColor
            
            }
            user2.viewColor();
            */
            /*
            // 一个函数可以当作另一个函数的参数传入
            var click = function(fn) {
                //...
                fn();
            }

            var mouseClick = function(){
                console.log("mouse click..");
            }

            var keyClick = function() {
                console.log("key click...");
            }
            mouseClick();
            click(mouseClick);
            click(keyClick);
            */

            
           /*
            var user = {
                name : "jack",
                age : 23,
                sayHello : function() {
                    console.log(this.name + " hahaha...");
                }
            }
            
            user.address = "jiaozuo";
            user.sayHi = function() {
                console.log("hi~~");
            }
           */
            

            /*
                var user = {};
                user.name = "jack";
                user.age = 23;
                user.sayHello = function(){
                    console.log("hello");
                }
            */

          
           /*
            function showUser(user) {
                console.log(user.name);
                console.log(user.age);
                console.log(user.address);
                user.sayHello();
                user.sayHi();
            }

            showUser(user);
           */
            
            

            // var user = {};
            // var user = new Object();

           /* var a = 20;
            console.log(a);

            var name;
            console.log(name.toString());
          */
        })();
        

        /*
        // "use strict";
        // 在javascript中没有块级作用域,但拥有函数级作用域
        if(1 == 1) {
            (function() {
                var num = 10;
                console.log(num);
            })();
            
        }
        console.log(num);
        */

        // var name;
        // console.log(name.toString());

        /*
        function fn() {
            var num = 10;
            function fn2() {
                console.log(num);
                console.log(name.toString());
            }   
            num ++;
            var name;
            return fn2;
        }
        
        fn()(); //11
       */



        /*function add(num1, num2) {
            var fn = function doAdd() {
                return num1 + num2;
            };
            return fn;
        }

        var res = add(12,23);
        var result = res();
        console.log(result);
        */

        // 闭包，定义在函数内部的函数
        // function outer() {
        //     function inner() {

        //     }
        // }
    
    </script>
</body>
</html>